package leetcode81_90;

import outoforder.leetcode.ListNode;

/**
 * @author shhjiang_001
 * @create 2020-06-24 11:28
 */
        /*
        给定一个排序链表，删除所有重复的元素，使得每个元素只出现一次。
        示例 1:
        输入: 1->1->2
        输出: 1->2
        */

public class Solution83 {
    public ListNode deleteDuplicates(ListNode head) {
        ListNode resNod = new ListNode();
        ListNode temp = resNod;
        if (head == null) return null;
        while (head.next != null){
            if (head.next.val > head.val){
                temp.next = new ListNode();

                temp = temp.next;
                temp.val = head.val;
            }
            head = head.next;
        }
        if (head.next == null){
            temp.next = new ListNode();
            temp = temp.next;
            temp.val = head.val;
        }
        return resNod.next;
    }
}
